import requests
from lxml import etree
header = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
}

f = open("分页参数分析及翻页爬取.txt",'w',encoding='utf-8')


for i in range(1,5):

    params={
        "pageno":i
    }
    response = requests.get(url='http://spiderbuf.cn/s04',params=params,headers=header)

    document = etree.HTML(response.text)

    trs = document.xpath('//tr')

    for item in trs:
        str = f''
        for td in item.xpath('./td'):
            str+=f'{td.text}\t|'
        f.write(str+"\n")
        print(str)
f.close()